package com.bank.controller;


import com.bank.exception.AuthenticationException;
import com.bank.model.ApiError;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;


public abstract class WebApiController {
    protected final int defaultPageSize = 5;

    @ExceptionHandler({AuthenticationException.class})
    @ResponseBody
    public ApiError handlerException(AuthenticationException exception,
                                     HttpServletResponse response) {

        ApiError apiError = new ApiError(exception.getMessage(), exception.getHttpStatus());
        response.setStatus(apiError.getStatus());
        return apiError;
    }
}
